<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>用户操作列表</title>
    <link href="${pageContext.request.contextPath}/css/bootstrap.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath }/js/bootstrap.js"></script>
    <style>
        #d1{
            text-decoration: none;
        }

        #d2{
            text-align: center;
        }
        #d3{
            width: 1500px;

            text-align: center;
        }
        .input-group{
            width:250px;
            float: left;
        }
        #p2{
            font-size: 40px;

        }
        #d4{
            margin-left: 150px;
            margin-top: 50px;
        }
        #d5{
            margin-left: 60px;
            margin-top: 50px;
        }
        #d6{
            margin-top: 50px;
            width: 120px;
            margin-left: 20px;
        }
        #but1{
            margin-top: 50px;
            margin-left: -250px;
            height: 33px;

        }
        #but2{
            margin-left: 50px;
            margin-top: 50px;
        }
        #but3{
            margin-top: 50px;
        }
        #d7{
            width: 1400px;
           margin-left: 80px;
            margin-top: 20px;
            height: 1000px;

        }
        #ta1{
            text-align: center;
        }
        #tr1{
            background-color: #D9EDF7;
        }

    </style>
</head>
<body>
    <div id="d1">当前账户：尊敬的<span style="color: #2aabd2">admin</span>您好，您可以
        <a href="${pageContext.request.contextPath }/customer/customerlist">返回客户列表</a>|
        <a href="login.jsp">退出当前账户</a></div>
    <div id="d2">
        <p id="p2">欢迎来到管理员后台管理系统</p>
        <div id="d3">
            <form action="${ pageContext.request.contextPath}/user/listWithCondition" method="post" class="form-inline">
                <div class="input-group" id="d4">
                    <span class="input-group-addon" id="sizing-addon2">帐号信息</span>
                    <input type="text" name="username" value="${ username }" class="form-control" placeholder="请输入您想要查询的帐号信息" aria-describedby="sizing-addon2" name="username" value="${ username }">
                </div>
                <div class="input-group" id="d5">
                    <span class="input-group-addon" id="sizing-addon3">注册时间</span>
                    <input type="datetime-local" name="regStart" value="${ regStart }" class="form-control" aria-describedby="sizing-addon2" name="regStart" value="${ regStart }">
                </div>
                <div class="input-group" id="d6">
                    <input type="datetime-local" name="regEnd" value="${ regEnd }"class="form-control" aria-describedby="sizing-addon2"  name="regEnd" value="${ regEnd }" >
                </div>
                <div class="input-group" style="margin-left:75px;margin-right: -215px">
                    <button  type="submit" class="btn btn-warning" id="but1">
                        <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                    </button>
                </div>
            </form>
            <div >
                <button class="btn btn-primary" id="but2" onclick="userListOperationWithMore('authorize')">批量授权</button>
                <button class="btn btn-danger" id="but3" onclick="userListOperationWithMore('resend')">批量重发</button>
            </div>
        </div>
        <div id="d7">
            <form method="post" id="listFormId">
                <table class="table table-bordered" id="ta1">
                        <tr id="tr1">
                            <td><input type="checkbox" onchange="selectOption(this.checked)"></td>
                            <td><b>序号</b></td>
                            <td><b>注册账号</b></td>
                            <td><b>注册邮箱</b></td>
                            <td><b>注册时间</b></td>
                            <td><b>激活状态</b></td>
                            <td><b>账号授权</b></td>
                            <td><b>当前状态</b></td>
                            <td><b>剩余时间</b></td>
                            <td><b>最后登入</b></td>
                            <td><b>操作</b></td>
                        </tr>
                <c:forEach  var="adminUser"  items="${adminUsers}" varStatus="status">
                    <tr>
                        <td><input type="checkbox" name="ids" value="${ adminUser.id }"></td>
                        <td>${status.count}</td>
                        <td>${adminUser.username}</td>
                        <td>${adminUser.email}</td>
                        <td>
                            <fmt:formatDate value="${ adminUser.regTime }" pattern="yyyy-MM-dd HH:mm:ss"/>
                        </td>
                        <td>
                            <c:if test="${adminUser.activeStatus eq 0}">未激活</c:if>
                            <c:if test="${adminUser.activeStatus eq 1}">已激活</c:if>
                        </td>
                        <td>
                            <c:if test="${adminUser.authorizeStatus eq 0}">未授权</c:if>
                            <c:if test="${adminUser.authorizeStatus eq 1}">已授权</c:if>
                        </td>
                        <td>
<%--                            && adminUser.countdown gt 0     || adminUser.countdown le 0--%>
                            <c:if test="${adminUser.loginFailCount ge 3 }">禁止登录</c:if>
                            <c:if test="${adminUser.loginFailCount lt 3 }">正常登录</c:if>
                        </td>
                        <td>
<%--                            <c:choose>--%>
<%--                                <c:when test="${ adminUser.loginFailCount }">--%>
<%--                                    ${adminUser.countdown}分钟--%>
<%--                                </c:when>--%>
<%--                                <c:otherwise>--%>
<%--                                    ---%>
<%--                                </c:otherwise>--%>
<%--                            </c:choose>--%>
                        </td>
                        <td>
                            <c:if test="${ empty adminUser.lastLoginTime }">无登录历史</c:if>
                            <c:if test="${ not empty adminUser.lastLoginTime }">
                                <fmt:formatDate value="${ adminUser.lastLoginTime }" pattern="yyyy-MM-dd HH:mm:ss"/>
                            </c:if>
                        </td>
                        <td>
                            <a class="btn btn-primary btn-sm" href="${ pageContext.request.contextPath }/user/resendEmail?id=${ adminUser.id }" onclick="return resendEmail(${ adminUser.activeStatus eq 0 });" <c:if test="${ adminUser.activeStatus eq 1 }">disabled="disabled"</c:if>>重发激活</a>
                            <c:if test="${ adminUser.authorizeStatus eq 1 }">
                                <a class="btn btn-danger btn-sm" href="${ pageContext.request.contextPath }/user/authorize?id=${ adminUser.id } &opr=0" >授权取消</a>
                            </c:if>
                            <c:if test="${ adminUser.authorizeStatus eq 0 }">
                                <a class="btn btn-warning btn-sm" href="${ pageContext.request.contextPath }/user/authorize?id=${ adminUser.id } &opr=1">授权通过</a>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
                </table>
            </form>
        </div>
    </div>
<script src="${pageContext.request.contextPath }/js/sys.js"></script>
<script>
    if(${ not empty msg }) {
        alert("${ msg }");
    }
    function userListOperationWithMore(opr) {
        //批量授权以及批量重发功能
        if(checkIsSelect("ids")) return;
        // 2.获取表单对象
        var formElem = document.getElementById("listFormId");
        // 3.判断当前按钮是用于重发还是用于授权的action值的设置
        if(opr == "authorize") {
            formElem.action = "${ pageContext.request.contextPath }/user/authorizeWithMore";
        } else {
            formElem.action = "${ pageContext.request.contextPath }/user/resendWithMore";
        }
        // 4.提交表单
        formElem.submit();
    }
    function resendEmail(sta) {
        if(!sta) return false;
        alert("重发激活成功");
        return true;
    }
    //全选按钮
    function selectOption(status) {
        selectAll(status,"ids")
    }
</script>
</body>
</html>
